from django.conf import settings
from libs.service.utils import make_sign
import requests

ws_info = settings.SERVICES['WEB_SOCKET']


def push_web_socket_message(message: str, uid: str = None, tag: str = None):
    params = {
        'AppId': ws_info['APP_ID'],
        'Message': message,
    }
    uid and params.update({'Uid': uid})
    tag and params.update({'Tag': tag})
    params = make_sign(ws_info['APP_SECRET'], 'POST', '/ws/push/', params)
    res = requests.post(ws_info['ENDPOINT'].rstrip('/') + '/ws/push/', params, verify=False)
    return res.json()
